package com.wicket.okrapp.biz.service.nb;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrapp.biz.service.dto.res.*;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrcomponent.integration.FwCompTemplateEngineClient;
import com.wicket.okrcomponent.integration.dto.QuerySemanticEngineDetailReqDto;
import com.wicket.okrcomponent.integration.dto.QuerySemanticEngineDetailRespDto;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import com.wicket.okrapp.biz.service.dto.req.GenerateSemanticContentReqDto;

import javax.annotation.Resource;
import java.util.Random;
import com.wicket.okrapp.biz.service.dto.req.ImplementAcceptFieldReqDto;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbStatusData {

    @Resource
    private FwCompTemplateEngineClient fwCompTemplateEngineClient;
/**
      * code:generateSemanticInstance
      * name:M3-生成语义内容
      * desc:undefined
      * gen by moon at 10/27/2022, 3:51:24 AM
      * 
      **/
     @Trace(operationName = "M3-生成语义内容")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public GenerateSemanticContentRespDto generateSemanticContent(GenerateSemanticContentReqDto reqDto) {
       // {systemDateTime}{randomNumberDigits}{targetContentName}批次

         boolean bRetFlag = false;
         GenerateSemanticContentRespDto retData = new GenerateSemanticContentRespDto();
         String retConent = "";
         QuerySemanticEngineDetailReqDto querySemanticEngineDetailReqDto = new QuerySemanticEngineDetailReqDto();
         querySemanticEngineDetailReqDto.setTemplateSemanticEngineCode("GENERATE_EVA_TEMP_BATCH_NAME");
         QuerySemanticEngineDetailRespDto querySemanticEngineDetailRespDto = fwCompTemplateEngineClient.querySemanticEngineDetail(querySemanticEngineDetailReqDto).getData();
         if(querySemanticEngineDetailRespDto!=null && querySemanticEngineDetailRespDto.getTemplateEngineTemplate()!=null){
             String systemDateTime = "\\{systemDateTime}";
             String randomNumberDigits = "\\{randomNumberDigits}";
             String targetContentName = "\\{targetContentName}";
             if(reqDto.getTargetContentName()!=null && !reqDto.getTargetContentName().isEmpty()){
                 bRetFlag = true;
                 retConent = querySemanticEngineDetailRespDto.getTemplateEngineTemplate().replaceAll(targetContentName,reqDto.getTargetContentName());
                 retConent = retConent.replaceAll(systemDateTime, CommonFunctionHelper.date2Str(CommonFunctionHelper.getCurrentTime()));
                 Random random = new Random();
                 String result="";
                 for (int i=0;i<reqDto.getRandomNumberDigits();i++)
                 {
                     result+=random.nextInt(10);
                 }
                 retConent = retConent.replaceAll(randomNumberDigits,result);
             }else{
                 retConent = querySemanticEngineDetailRespDto.getTemplateEngineTemplate().replaceAll(targetContentName,"---");
             }

             if(retConent!=null && !retConent.isEmpty()){
                 retConent = retConent.replaceAll("---","");
                 retConent = retConent.replaceAll("（）","");
                 retData.setObjectName(retConent);
             }

             if(bRetFlag){
                 return retData;
             }

         }
         return retData;
      }
/**
      * code:receptionService
      * name:M3执行接收字段入参（特殊方法）
      * desc:undefined
      * gen by moon at 4/20/2023, 1:33:59 AM
      *
      **/
     @Trace(operationName = "M3执行接收字段入参（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementAcceptFieldRespDto implementAcceptField(ImplementAcceptFieldReqDto reqDto) {
         return BeanUtil.toBean(reqDto, ImplementAcceptFieldRespDto.class);
      }
  //手工接入方法
}
